#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 2e5 + 5;
const int M = 1e9 + 7;

int n, u, v;

struct Edge {
    int to, next;
} e[N << 1];

int head[N], idx = 1, siz[N];
ll ans[N];

void add_edge(int u, int v) {
    e[idx].to = v;
    e[idx].next = head[u];
    head[u] = idx++;
}
void clear_graph() {
    memset(head, -1, sizeof(head));
    memset(e, 0, sizeof(e));
    idx = 1;

    for (int i = 1; i < N; i++) siz[i] = 1;
}

void dfs1(int u, int f = -1, int dep = 0) {
    ans[1] += dep;
    for (int i = head[u]; ~i; i = e[i].next) {
        int j = e[i].to;
        if (j != f) {
            dfs1(j, u, dep + 1);
            siz[u] += siz[j];
        }
    }
}

void dfs2(int u, int f = -1) {
    for (int i = head[u]; ~i; i = e[i].next) {
        int j = e[i].to;
        if (j != f) {
            ans[j] = ans[u] + n - siz[j] * 2;
            dfs2(j, u);
        }
    }
}
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);

    cin >> n;
    clear_graph();
    for (int i = 1; i <= n - 1; i++) {
        cin >> u >> v;
        add_edge(u, v), add_edge(v, u);
    }

    dfs1(1);
    dfs2(1);

    for (int i = 1; i <= n; i++)
        cout << ans[i] << endl;
    return 0;
}